package com.cwd.arm.inter.controller;

import com.cwd.arm.application.dto.MsgDto;
import com.cwd.arm.application.dto.board.*;
import com.cwd.arm.application.service.read.facade.BoardReadService;
import com.cwd.arm.application.service.read.facade.MsgReadService;
import com.cwd.arm.inter.util.DtoToVoUtil;
import com.cwd.arm.inter.vo.ResponseVo;
import com.cwd.arm.inter.vo.board.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
* Description:消息
* Created on 2022年01月15日
* @author  yan
*/
@Api(value = "主页接口", description = "主页接口")
@RestController
@RequestMapping(value = "/board")
public class BoardController {

    @Autowired
    private MsgReadService readService;

    @Autowired
    private BoardReadService boardReadService;

    @ApiOperation(value = "查询消息信息", notes = "查询消息信息")
    @ApiImplicitParams(value = {
    @ApiImplicitParam(name = "id", value = "消息id",required = true,dataType = "Long", paramType = "path")
    })
    @GetMapping("/msg/{id}")
    public ResponseVo<MsgVo> getMsg(@PathVariable Long id) {
        MsgDto dto = readService.selectById(id);
        return ResponseVo.<MsgVo>BUILDER().success(DtoToVoUtil.convertToVo(dto));
    }

    @ApiOperation(value = "查询全部需要展示的消息", notes = "查询全部需要展示的消息")
    @GetMapping("/msg")
    public ResponseVo<List<MsgVo>> getMsgList() {
        List<MsgDto> dtoList = readService.getCurrentUserMsgList();
        return ResponseVo.<List<MsgVo>>BUILDER().success(DtoToVoUtil.convertToMsgVoList(dtoList));
    }

    @ApiOperation(value = "实时合计", notes = "实时合计")
    @GetMapping("/rt")
    public ResponseVo<RtVo> getRt() {
        RtDto rtDto = boardReadService.getRt();
        return ResponseVo.<RtVo>BUILDER().success(DtoToVoUtil.convertToVo(rtDto));
    }

    @ApiOperation(value = "每月现金流", notes = "每月现金流")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "year", value = "年如:2022",required = true,dataType = "int")
    })
    @GetMapping("/month/cash/amount")
    public ResponseVo<List<MonthAmountVo>> getMonthCashAmount(Integer year) {
        List<MonthAmountDto> dtoList = boardReadService.getMonthCashAmount(year);
        return ResponseVo.<List<MonthAmountVo>>BUILDER().success(DtoToVoUtil.convertToMonthAmountVoList(dtoList));
    }

    @ApiOperation(value = "每月应收账款完成率", notes = "每月应收账款完成率")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "year", value = "年如:2022",required = true,dataType = "int")
    })
    @GetMapping("/month/receivable/rate")
    public ResponseVo<List<MonthRateVo>> getMonthReceivableRate(Integer year) {
        List<MonthRateDto> dtoList = boardReadService.getMonthReceivableRate(year);
        return ResponseVo.<List<MonthRateVo>>BUILDER().success(DtoToVoUtil.convertToMonthRateVoList(dtoList));
    }

    @ApiOperation(value = "每季度确认收入", notes = "每季度确认收入")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "year", value = "年如:2022",required = true,dataType = "int")
    })
    @GetMapping("/q/confirm/amount")
    public ResponseVo<List<QAmountVo>> getQMonthConfirmAmount(Integer year) {
        List<QAmountDto> dtoList = boardReadService.getQMonthConfirmAmount(year);
        return ResponseVo.<List<QAmountVo>>BUILDER().success(DtoToVoUtil.convertToQAmountVoList(dtoList));
    }

    @ApiOperation(value = "历年确认收入", notes = "历年确认收入")
    @GetMapping("/year/confirm/amount")
    public ResponseVo<List<YearAmountVo>> getYearConfirmAmount() {
        List<YearAmountDto> dtoList = boardReadService.getYearConfirmAmount();
        return ResponseVo.<List<YearAmountVo>>BUILDER().success(DtoToVoUtil.convertToYearAmountVoList(dtoList));
    }

    @ApiOperation(value = "实时收款比例(返回data为已收比例)", notes = "实时收款比例(返回data为已收比例)")
    @GetMapping("/received/rate")
    public ResponseVo<BigDecimal> getReceivedRate() {
        BigDecimal rt = boardReadService.getReceivedRate();
        return ResponseVo.<BigDecimal>BUILDER().success(rt);
    }

    @ApiOperation(value = "确认收入完成率(返回data为已完成比例)", notes = "确认收入完成率(返回data为已完成比例)")
    @GetMapping("/confirm/rate")
    public ResponseVo<BigDecimal> getConfirmRate() {
        BigDecimal ct = boardReadService.getConfirmRate();
        return ResponseVo.<BigDecimal>BUILDER().success(ct);
    }

}
